<template>
	<view class="page">
		<view class="list">
			<view class="item" v-for="(item,index) in accountList" :key="index" @click="changeBindInfo(item)">
				<image class="cover" :src="imgBaseUrl3+item.photo" mode=""></image>
				<view class="info">
					<view class="name">
						{{item.name}} <text>({{item.code}})</text>
					</view>
					<text>{{item.departName}}</text>
				</view>
				<view class="check" v-if="item.checked">
					<u-icon name="checkmark" color="#2979ff" size="28"></u-icon>
				</view>
			</view>
		</view>
		<view class="addBtn" @click="handleAddAccount">
			<u-icon name="plus-circle" color="#2979ff" size="28"></u-icon>
			{{language.switchBind.addBtn}}
		</view>
	</view>
</template>

<script>
	import {getPersonApi,} from '@/common/api/commonApi/commonApi.js'
	export default {
		data() {
			return {
				accountList:[]
			}
		},
		methods: {
			changeBindInfo(item){
				console.log(item);
				uni.setStorageSync('selectInfoAccount',item)
				this.goBack()
			},
			handleAddAccount(){
				uni.showModal({
					title: '提示',
					content: '是否进行绑定操作？',
					success:(res)=> {
						if (res.confirm) {
							this.goPage('/pages/componentsA/bingInfo/bingInfo')
						} 
					}
				})
			},
			getRemberAccount(){
				let selectInfoAccount = uni.getStorageSync('selectInfoAccount')
				getPersonApi({
					personId: selectInfoAccount.id ? selectInfoAccount.id : ''
				}).then(res=>{
					this.accountList = res.result.personList
					let selectAccount = uni.getStorageSync('selectInfoAccount')
					this.accountList.forEach(item=>{
						if(item.id==selectAccount.id) item.checked = true
					})
				})
			}
		},
		onLoad() {
		},
		onShow() {
			this.setPageTitle(this.language.switchBind.title)
			this.getRemberAccount()
		},
	}
</script>

<style lang="scss" scoped>
.page{
	background-color: #fff;
	height: 100vh;
	padding-top: 40rpx;
	.list{
		border-top: 2rpx solid #dcdcdc;
		.item{
			display: flex;
			align-items: center;
			height: 120rpx;
			border-bottom: 2rpx solid #dcdcdc;
			.cover{
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				background-color: #c6deff;
				margin: 0 20rpx;
			}
			.info{
				flex: 1;
				.name{
					font-size: 34rpx;
					color: #333;
					text{
						margin-left: 10rpx;
					}
				}
				text{
					color: #999;
					font-size: 28rpx;
				}
			}
			.check{
				width: 120rpx;
				@include flexCenter;
				image{
					width: 70rpx;
					height: 70rpx;
				}
			}
		}
	}
	.addBtn{
		padding: 10rpx 15rpx;
		color: #4089f0;
		display: flex;
		align-items: center;
		font-size: 32rpx;
		.icon{
			width: 60rpx;
			height: 60rpx;
			margin-right: 10rpx;
		}
	}
}
</style>
